package com.gxa.modules.property.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxa.modules.property.dto.NoticeToAdd;
import com.gxa.modules.property.dto.NoticeToUpdate;
import com.gxa.modules.property.entity.Notice;
import com.gxa.modules.property.entity.Urgency;
import com.gxa.modules.property.mapper.NoticeMapper;
import com.gxa.modules.property.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class NoticeServiceImpl  implements NoticeService {
    @Autowired
    private NoticeMapper noticeMapper;
    @Override
    public void add(NoticeToAdd noticeToAdd) {
        this.noticeMapper.add(noticeToAdd);
    }

    @Override
    public void delete(Integer id) {
        this.noticeMapper.delete(id);
    }

    @Override
    public void update(NoticeToUpdate noticeToUpdate) {
        this.noticeMapper.update(noticeToUpdate);
    }

    @Override
    public PageInfo<Notice> queryNotice(Map<String, Object> params) {
        String page1 = (String) params.get("page");
        String limit1 = (String) params.get("limit");
        Integer page = Integer.valueOf(page1);
        Integer limit = Integer.valueOf(limit1);

        //条件查询
        String noticeTitle = (String) params.get("noticeTitle");
        String communityId = (String) params.get("communityId");

        PageHelper.startPage(page,limit);
        List<Notice> noticeList = noticeMapper.queryNotice(noticeTitle,communityId);
        PageInfo<Notice> pageInfo = new PageInfo<>(noticeList);

        return pageInfo;
    }

    @Override
    public void deleteNoticeByIds(List<Integer> ids) {
        noticeMapper.deleteNoticeByIds(ids);
    }


}
